package common.kit;

import java.math.BigDecimal;

/**
 * 统计代码执行时间
 * @author phoooob
 *
 */
public class TimeCountKit {
	String name = "" ;
	Long startTime ;
	Long endTime ;
	
	public Long getStartTime() {
		return startTime;
	}

	public void setStartTime(Long startTime) {
		this.startTime = startTime;
	}

	public Long getEndTime() {
		return endTime;
	}

	public void setEndTime(Long endTime) {
		this.endTime = endTime;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static TimeCountKit start() {
		return TimeCountKit.start("--");
	}
	
	public static TimeCountKit start(String name) {
		TimeCountKit timeCountKit = new TimeCountKit() ;
		timeCountKit.setStartTime(System.currentTimeMillis());
		timeCountKit.setName(name);
		return timeCountKit ;
	}
	
	public void end() {
		this.setEndTime(System.currentTimeMillis());
		Long mills = getEndTime() - getStartTime() ;
		BigDecimal secs = new BigDecimal(mills).divide(new BigDecimal(1000)).setScale(2,BigDecimal.ROUND_HALF_UP);
		System.out.println( name + "累计用时：" + mills + "毫秒，" + secs + "秒。");
	}
	
}
